﻿using System;
using System.Linq;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections.Generic;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Framework.Client;
using Microsoft.LightSwitch.Presentation;
using Microsoft.LightSwitch.Presentation.Extensions;
namespace LightSwitchApplication
{
    public partial class SearchFilteredStates
    {
        partial void SearchFilteredStates_InitializeDataWorkspace(List<IDataService> saveChangesTo)
        {
            if (this.Application.User.HasPermission(Permissions.CanEditGeography))//admin
            {

            }
            else if (this.Application.User.HasPermission(Permissions.CanSearchShop) && this.Application.User.HasPermission(Permissions.CanManageMyShop))
            {
                this.SalesPersonId = -1;
                string userName = this.Application.User.FullName;
                //sales person - regional manager
                foreach (SalesPerson item in this.DataWorkspace.ApplicationData.SalesPersons)
                {
                    if (item.aspnet_Profile != null && item.aspnet_Profile.PropertyValuesString == userName)
                    {
                        this.SalesPersonId = item.Id;
                        break;
                    }
                }
            }
            else
            {
                this.SalesPersonId = -1;
            }

        }

        partial void Cancel_Execute()
        {
            this.Close(false);
        }
    }
}
